import request from "@/utils/request.js"
import store from "../store";

const baseApi = 'jtp'

// 报销申请 - 获取全部的的报销申请单
export function getTravelApplyList(page) {
    return request({
        module: baseApi,
        url: '/',
        showLoading: true,
        data: {"applicationStatus": "04", "appType": "03", "current": page, "size": 10},
        trCode: 'PROXY01025'
    })
}

export function getTravelCities() {
    return new Promise(resolve => {
        let hotelCitys = store.getters.getHotelCitys();
        if (hotelCitys) {
            resolve(hotelCitys);
        } else {
            request({
                module: baseApi,
                showLoading: true,
                url: '/',
                data: {"appType": "03", supplierNo: "501"},
                trCode: 'PROXY00139'

            }).then(res => {
                const citys = res[1].data.cityList.data.cities;
                store.dispatch("setHotelCitys", citys);
                console.log("store.getters.getHotelCitys()",store.getters.getHotelCitys())
                resolve(store.getters.getHotelCitys());
            })
        }
    })
}

export function getFlyCities() {
    return new Promise(resolve => {
        let planeCitys = store.getters.getObtainPlaneCitys();
        if (planeCitys) {
            resolve(planeCitys);
        } else {
            request({
                module: baseApi,
                showLoading: true,
                url: '/',
                data: {supplier: "501"},
                trCode: 'PROXY00098'
            }).then(res => {
                const citys = res[1].data;
                store.dispatch("setObtainPlaneCitys", citys);
                console.log("store.getters.setObtainPlaneCitys()",store.getters.getObtainPlaneCitys())
                resolve(store.getters.getObtainPlaneCitys());
            })
        }
    })

}

export function getTrainCities() {
    return new Promise(resolve => {
        let planeCitys = store.getters.getObtainTrainCitys();
        if (planeCitys) {
            resolve(planeCitys);
        } else {
            request({
                module: baseApi,
                showLoading: true,
                url: '/',
                data: {supplier: "501"},
                trCode: 'PROXY00151'
            }).then(res => {
                const citys = res[1].data;
                store.dispatch("setObtainTrainCitys", citys);
                resolve(store.getters.getObtainTrainCitys());
            })
        }
    })

}

export function getStantader() {
    return request({
        module: baseApi,
        showLoading: true,
        url: '/',
        data: {"businessType": "03"},
        trCode: 'PROXY00144'
    })
}